package com.hp.erp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hp.erp.entity.JsonResult;
import com.hp.erp.entity.RoleFun;
import com.hp.erp.service.IRoleFunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class RoleFunctionsController {

    @Autowired
    private IRoleFunService roleFunService;

    @PostMapping("/role-functions")
    public JsonResult addRoleFunctions(@RequestBody RoleFun roleFun){
        roleFunService.save(roleFun);
        //考虑是上级权限的情况
        return new JsonResult(1,roleFun);
    }

    @DeleteMapping("/role-functions/{roleId}/{functionsId}")
    public JsonResult deleteRoleFunctions(@PathVariable String roleId,@PathVariable String functionsId){
        roleFunService.remove(new QueryWrapper<RoleFun>()
                .lambda()
                .eq(RoleFun::getRoleId,roleId)
                .eq(RoleFun::getFunId,functionsId));
        //考虑是上级权限的情况
        return new JsonResult(1,null);
    }
}
